package com.yunkaweilai.android.view.popup;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.github.lazylibrary.util.StringUtils;
import com.google.gson.Gson;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.interfaces.PopupDiscountSelector;
import com.yunkaweilai.android.interfaces.PopupIntegralMortgage;
import com.yunkaweilai.android.model.member.MemberHeadModel;
import com.yunkaweilai.android.model.member.PreferentiaActivitiesModel;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.Utils;
import com.yunkaweilai.android.view.MyToast;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.ArrayList;

import razerdp.basepopup.BasePopupWindow;

/**
 * Created by Administrator on 2017/7/17.
 */

public class IntegralMortgagePopup extends BasePopupWindow implements View.OnClickListener {

    private View popupView;
    private Activity mContext;
    private PopupIntegralMortgage popupIntegralMortgage;
    private MemberHeadModel model;
    private TextView idTvIntegralRule;
    private EditText idEdtIntegeral;

    public IntegralMortgagePopup(Activity context, MemberHeadModel model) {
        super(context);
        this.model = model;
        this.mContext = context;
        bindEvent();
    }
    public void setPopupInterfaces(PopupIntegralMortgage popupIntegralMortgage){
        this.popupIntegralMortgage = popupIntegralMortgage;
    }

    @Override
    protected Animation initShowAnimation() {
        return getTranslateAnimation(250 * 2, 0, 300);
    }

    @Override
    public View getClickToDismissView() {
        return popupView.findViewById(R.id.id_img_close);
    }

    @Override
    public View onCreatePopupView() {
        popupView = LayoutInflater.from(getContext()).inflate(R.layout.popup_integral_mortgage, null);
        return popupView;
    }

    @Override
    public View initAnimaView() {
        return popupView.findViewById(R.id.id_rlayout_bottom);
    }

    private void bindEvent() {
        if (popupView != null) {
            popupView.findViewById(R.id.id_tv_right).setOnClickListener(this);
            popupView.findViewById(R.id.id_tv_clean).setOnClickListener(this);
            idTvIntegralRule = ((TextView) popupView.findViewById(R.id.id_tv_integral_rule));
            idEdtIntegeral = ((EditText) popupView.findViewById(R.id.id_edt_integeral));
            idTvIntegralRule.setText("共" +  model.getMember_points() + "积分，每" + model.getArrived_amount() + "积分抵1元");
        }
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.id_tv_right:
                if (StringUtils.isEmpty(idEdtIntegeral.getText().toString())){
                    MyToast.showShortToast(mContext,"还未填写积分");
                }else if (Float.parseFloat(idEdtIntegeral.getText().toString()) > Float.parseFloat(model.getMember_points())){
                    MyToast.showShortToast(mContext,"积分不足");
                }else if (Float.parseFloat(idEdtIntegeral.getText().toString()) <= 0){
                    MyToast.showShortToast(mContext,"积分不能填写0或负数");
                }else{
                    popupIntegralMortgage.updateInfo(idEdtIntegeral.getText().toString(),"",true);
                    dismiss();
                }
                break;
            case R.id.id_tv_clean:
                popupIntegralMortgage.updateInfo("0","0",false);
                dismiss();
                break;
        }
    }
}